import javafx.scene.control.TableCell;
import javafx.scene.control.TextField;

public class SelectableTextCell<S, T> extends TableCell<S, T> {
    private final TextField textField;

    public SelectableTextCell() {
        this.textField = new TextField();
        this.textField.setEditable(false); // 禁止编辑
        this.textField.setStyle("-fx-background-color: transparent;"); // 设置背景透明
    }

    @Override
    protected void updateItem(T item, boolean empty) {
        super.updateItem(item, empty);

        if (empty || item == null) {
            setText(null);
            setGraphic(null);
        } else {
            textField.setText(item.toString());
            setGraphic(textField);
        }
    }
}